Skip to content

fix(TextInput): fall back to theme fontWeight to prevent SIGSEGV on Fabric#4880

Open
isaacrowntree wants to merge 1 commit intocallstack:mainfrom
isaacrowntree:fix/textinput-fontweight-undefined-sigsegv
Open

fix(TextInput): fall back to theme fontWeight to prevent SIGSEGV on Fabric#4880
isaacrowntree wants to merge 1 commit intocallstack:mainfrom
isaacrowntree:fix/textinput-fontweight-undefined-sigsegv

Conversation

@isaacrowntree
Copy link

@isaacrowntree isaacrowntree commented Mar 20, 2026

Motivation

TextInputOutlined and TextInputFlat destructure fontWeight from the user's style prop and spread it after the theme font object:

const { fontWeight } = (StyleSheet.flatten(style) || {}) as TextStyle;
// ...
textStyle: { ...font, fontSize, lineHeight, fontWeight }

When the user doesn't provide fontWeight in their style (the common case — most <TextInput> usage omits it), the destructured value is undefined. Spreading { ...font, fontWeight: undefined } then overrides font.fontWeight (e.g. '400' from the theme) with undefined.

On React Native's Fabric renderer (New Architecture), this undefined flows as nil to the native RCTGetFontWeight function, which passes it to CFStringFindCFStringGetLength on a NULL pointer → EXC_BAD_ACCESS (SIGSEGV).

This is a fatal crash that kills the app on any screen with a <TextInput> that doesn't explicitly set fontWeight in its style prop. Reproduced on iOS with React Native 0.78 + react-native-paper 5.15.0 + Fabric enabled.

Related issue

No existing issue — discovered via Crashlytics crash report in production. Native crash stack:

Thread 4 Crashed:
0  CoreFoundation    CF_IS_OBJC + 12
1  CoreFoundation    CFStringGetLength + 232
2  CoreFoundation    CFStringFind + 60
3  React             RCTGetFontWeight + 212
4  React             RCTFontWithFontProperties + 3024
5  React             RCTNSTextAttributesFromTextAttributes + 316
6  React             RCTNSAttributedStringFromAttributedString + 364
7  React             -[RCTTextLayoutManager measureAttributedString:...] + 76

Test plan

  1. Render <TextInput mode="outlined" /> without a fontWeight in the style prop → previously crashes on Fabric, now uses theme font's fontWeight
  2. Render <TextInput mode="outlined" style={{ fontWeight: '700' }} /> → still applies the user-provided weight (nullish coalescing only kicks in for undefined/null)
  3. Both TextInputOutlined and TextInputFlat are patched with the same fix
  4. Lint, TypeScript, and tests should pass — the change is a single-line nullish coalescing fallback per file

…ide one

Both TextInputOutlined and TextInputFlat destructure `fontWeight` from the
user's `style` prop and spread it after the theme font object:

    const { fontWeight } = StyleSheet.flatten(style) || {};
    textStyle: { ...font, fontWeight }

When the user doesn't set `fontWeight` in their style, the destructured
value is `undefined`. Spreading `{ ...font, fontWeight: undefined }` then
overrides `font.fontWeight` (e.g. '400' from the theme) with `undefined`.

On React Native's Fabric renderer (New Architecture), this `undefined`
flows through as nil to the native `RCTGetFontWeight` function, which
passes it to `CFStringFind` → `CFStringGetLength` on a NULL pointer →
EXC_BAD_ACCESS (SIGSEGV).

The fix renames the destructured variable to `fontWeightStyle` and uses
nullish coalescing to fall back to the theme font's fontWeight:

    const fontWeight = fontWeightStyle ?? font.fontWeight;

This preserves the existing behavior when `fontWeight` IS provided in the
style prop, while preventing the nil crash when it isn't.
@callstack-bot
Copy link

Hey @isaacrowntree, thank you for your pull request 🤗. The documentation from this branch can be viewed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants